//
//  MCXinZhiDuTableViewCell.m
//  TLYL
//
//  Created by cai miao on 2018/1/8.
//  Copyright © 2018年 TLYL01. All rights reserved.
//

#import "MCXinZhiDuTableViewCell.h"
#import "MCXinZhiDuReportTotalModel.h"
#import "MCXinZhiDuReportLotteryModel.h"
#import "MCDataTool.h"
@interface MCXinZhiDuTableViewCell()
/** xingming*/
@property (nonatomic,weak) UILabel *nameLabel;
/** tuandui*/
@property (nonatomic,weak) UILabel *titlesubLabel;
/** 类型*/
@property (nonatomic,weak) UILabel *typeLabel;
/** 充值*/
@property (nonatomic,weak) UILabel *chongzhiLabel;
/** 提款*/
@property (nonatomic,weak) UILabel *tikuanLabel;
/** 购彩*/
@property (nonatomic,weak) UILabel *goucaiLabel;

@property (nonatomic,weak) UILabel *kuiSunValueLabel;
@property (nonatomic,weak) UILabel *qitaValueLabel;

@property (nonatomic,weak) UIView *bgView;
@end

@implementation MCXinZhiDuTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setUpUI];
    }
    return self;
}

- (void)setUpUI{
    UIView *bgView1 = [[UIView alloc] init];
    [self addSubview:bgView1];
    bgView1.layer.cornerRadius = 6;
    bgView1.clipsToBounds = YES;
    [bgView1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(MC_REALVALUE(13));
        make.right.equalTo(self).offset(MC_REALVALUE(-13));
        make.top.equalTo(self).offset(MC_REALVALUE(10));
        make.bottom.equalTo(self).offset(MC_REALVALUE(0));
    }];
    bgView1.backgroundColor = [UIColor whiteColor];
    
    self.backgroundColor = RGB(231, 231, 231);
    CGFloat font = MC_REALVALUE(12);
    UIImageView *titleImageV = [[UIImageView alloc] init];
    [bgView1 addSubview:titleImageV];
    titleImageV.image = [UIImage imageNamed:@"dlgl-tdbb-xz"];
    [titleImageV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(bgView1).offset(MC_REALVALUE(22));
        make.top.equalTo(bgView1).offset(MC_REALVALUE(16));
        make.height.width.equalTo(@(MC_REALVALUE(22)));
    }];
    UILabel *titleLabel = [[UILabel alloc] init];
    [bgView1 addSubview:titleLabel];
    titleLabel.font = [UIFont boldSystemFontOfSize:font];
    titleLabel.textAlignment = NSTextAlignmentLeft;


    self.nameLabel = titleLabel;
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(titleImageV.mas_right).offset(MC_REALVALUE(7));
        make.centerY.equalTo(titleImageV);
    }];


    UILabel *subTitleLabel = [[UILabel alloc] init];
    [bgView1 addSubview:subTitleLabel];
    subTitleLabel.font = [UIFont systemFontOfSize:font];
    subTitleLabel.textAlignment = NSTextAlignmentLeft;
    subTitleLabel.textColor = RGB(102, 102, 102);
    self.titlesubLabel = subTitleLabel;
    [subTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(titleLabel.mas_right).offset(MC_REALVALUE(8));
        make.centerY.equalTo(titleImageV);
    }];

    UIView *bgView = [[UIView alloc] init];
    [bgView1 addSubview:bgView];
    bgView.layer.cornerRadius = 5;
    bgView.clipsToBounds = YES;
    bgView.backgroundColor = [UIColor colorWithHexString:@"#eff7ff"];
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(titleImageV);
        make.top.equalTo(titleImageV.mas_bottom).offset(MC_REALVALUE(11));
        make.right.equalTo(self).offset(MC_REALVALUE(-27));
        make.height.equalTo(@(MC_REALVALUE(105)));
    }];
    
    CGFloat topPadding = MC_REALVALUE(12.5);
    CGFloat vPadding = MC_REALVALUE(0);
    CGFloat w = MC_REALVALUE(80);
    UILabel *yueLabel = [[UILabel alloc] init];
    [bgView addSubview:yueLabel];
    yueLabel.font = [UIFont systemFontOfSize:font];
    yueLabel.textAlignment = NSTextAlignmentLeft;
    yueLabel.text = @"购彩：";
    yueLabel.textColor = RGB(46, 46, 46);
    [yueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(bgView).offset(MC_REALVALUE(10));
        make.top.equalTo(bgView).offset(MC_REALVALUE(19));
    }];
    
    UILabel *yueValueLabel = [[UILabel alloc] init];
    [bgView addSubview:yueValueLabel];
    yueValueLabel.font = [UIFont systemFontOfSize:font];
    yueValueLabel.textAlignment = NSTextAlignmentLeft;
    yueValueLabel.text = @"加载中";
    yueValueLabel.numberOfLines = 0;
    self.typeLabel = yueValueLabel;
    yueValueLabel.textColor = RGB(102, 102, 102);
    [yueValueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(yueLabel.mas_right).offset(vPadding);
        make.top.equalTo(yueLabel);
    }];
    
    UILabel *personLabel = [[UILabel alloc] init];
    [bgView addSubview:personLabel];
    personLabel.font = [UIFont systemFontOfSize:font];
    personLabel.textAlignment = NSTextAlignmentLeft;
    personLabel.text = @"返点：";
    personLabel.textColor = RGB(46, 46, 46);
    [personLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(bgView.mas_left).offset(MC_REALVALUE(167));
        make.top.equalTo(yueLabel);
    }];
    
    UILabel *personValueLabel = [[UILabel alloc] init];
    [bgView addSubview:personValueLabel];
    personValueLabel.font = [UIFont systemFontOfSize:font];
    personValueLabel.textAlignment = NSTextAlignmentLeft;
    personValueLabel.text = @"加载中";
    personValueLabel.numberOfLines = 0;
    self.chongzhiLabel = personValueLabel;
    personValueLabel.textColor = RGB(102, 102, 102);
    [personValueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(personLabel.mas_right).offset(vPadding);
        make.top.equalTo(yueLabel);
        make.width.equalTo(@(w));
    }];
    
    self.bgView = bgView;
    
    UILabel *chongzhiLabel = [[UILabel alloc] init];
    [bgView addSubview:chongzhiLabel];
    chongzhiLabel.font = [UIFont systemFontOfSize:font];
    chongzhiLabel.textAlignment = NSTextAlignmentLeft;
    chongzhiLabel.text = @"中奖：";
    chongzhiLabel.textColor = RGB(46, 46, 46);
    [chongzhiLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(yueLabel);
        make.top.equalTo(yueLabel.mas_bottom).offset(topPadding);
    }];
    
    UILabel *chongzhiValueLabel = [[UILabel alloc] init];
    [bgView addSubview:chongzhiValueLabel];
    chongzhiValueLabel.font = [UIFont systemFontOfSize:font];
    chongzhiValueLabel.textAlignment = NSTextAlignmentLeft;
    self.tikuanLabel = chongzhiValueLabel;
    chongzhiValueLabel.text = @"加载中";
    chongzhiValueLabel.numberOfLines = 0;
    chongzhiValueLabel.textColor = RGB(102, 102, 102);
    [chongzhiValueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(chongzhiLabel.mas_right).offset(vPadding);
        make.top.equalTo(chongzhiLabel);
        make.width.equalTo(@(w));
    }];
    
    UILabel *tixianLabel = [[UILabel alloc] init];
    [bgView addSubview:tixianLabel];
    tixianLabel.font = [UIFont systemFontOfSize:font];
    tixianLabel.textAlignment = NSTextAlignmentLeft;
    tixianLabel.text = @"盈亏：";
    tixianLabel.textColor = RGB(46, 46, 46);
    [tixianLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(bgView.mas_left).offset(MC_REALVALUE(167));
        make.top.equalTo(chongzhiLabel);
    }];
    
    UILabel *tixianValueLabel = [[UILabel alloc] init];
    [bgView addSubview:tixianValueLabel];
    tixianValueLabel.font = [UIFont systemFontOfSize:font];
    tixianValueLabel.textAlignment = NSTextAlignmentLeft;
    tixianValueLabel.text = @"加载中";
    tixianValueLabel.numberOfLines = 0;
    self.goucaiLabel = tixianValueLabel;
    tixianValueLabel.textColor = RGB(102, 102, 102);
    [tixianValueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(tixianLabel.mas_right).offset(vPadding);
        make.top.equalTo(chongzhiLabel);
        make.width.equalTo(@(w));
    }];
    
    UILabel *kuiSunLabel = [[UILabel alloc] init];
    [bgView addSubview:kuiSunLabel];
    kuiSunLabel.font = [UIFont systemFontOfSize:font];
    kuiSunLabel.textAlignment = NSTextAlignmentLeft;
    kuiSunLabel.text = @"亏损(不平账)：";
    kuiSunLabel.textColor = RGB(46, 46, 46);
    [kuiSunLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(yueLabel);
        make.top.equalTo(tixianLabel.mas_bottom).offset(topPadding);
    }];
    
    UILabel *kuiSunValueLabel = [[UILabel alloc] init];
    [bgView addSubview:kuiSunValueLabel];
    kuiSunValueLabel.font = [UIFont systemFontOfSize:font];
    kuiSunValueLabel.textAlignment = NSTextAlignmentLeft;
    kuiSunValueLabel.text = @"加载中";
    kuiSunValueLabel.numberOfLines = 0;
    self.kuiSunValueLabel = kuiSunValueLabel;
    kuiSunValueLabel.textColor = RGB(102, 102, 102);
    [kuiSunValueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(kuiSunLabel.mas_right).offset(vPadding);
        make.top.equalTo(kuiSunLabel);
        make.width.equalTo(@(w));
    }];
    
    
    UILabel *qitaLabel = [[UILabel alloc] init];
    [bgView addSubview:qitaLabel];
    qitaLabel.font = [UIFont systemFontOfSize:font];
    qitaLabel.textAlignment = NSTextAlignmentLeft;
    qitaLabel.text = @"其他收入：";
    qitaLabel.textColor = RGB(46, 46, 46);
    [qitaLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(tixianLabel);
        make.top.equalTo(kuiSunLabel);
    }];
    
    UILabel *qitaValueLabel = [[UILabel alloc] init];
    [bgView addSubview:qitaValueLabel];
    
    qitaValueLabel.font = [UIFont systemFontOfSize:font];
    qitaValueLabel.textAlignment = NSTextAlignmentLeft;
    qitaValueLabel.text = @"加载中";
    qitaValueLabel.numberOfLines = 0;
    self.qitaValueLabel = qitaValueLabel;
    qitaValueLabel.textColor = RGB(102, 102, 102);
    [qitaValueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(qitaLabel.mas_right).offset(vPadding);
        make.top.equalTo(qitaLabel);
        make.width.equalTo(@(w));
    }];
}



-(void)setDataSource:(MCXinZhiDuReportListModel *)dataSource{
    _dataSource = dataSource;


    self.typeLabel.text = GetRealSNum(dataSource.BetMoney);
    self.chongzhiLabel.text = GetRealSNum(dataSource.RebateMoney);
    self.tikuanLabel.text = GetRealSNum(dataSource.WinnMoney);
    self.goucaiLabel.text = GetRealSNum(dataSource.LossMoney);
    self.kuiSunValueLabel.text = GetRealSNum(dataSource.NoLossAccountMoney);
    self.qitaValueLabel.text = RemoveMeaninglessZero(dataSource.OtherMoney);
    [MCDataTool changeYKLabelColor:self.kuiSunValueLabel];
    int chidNum = [dataSource.ChildNum intValue];
    if (chidNum > 0) {
        self.nameLabel.textColor = [UIColor redColor];
    } else {
        self.nameLabel.textColor = [UIColor blackColor];
    }
    self.titlesubLabel.text = [NSString stringWithFormat:@"活跃人数:%@",GetRealSNum(dataSource.ActiveNumber)];
    if (self.isSelf == 1) {
        self.nameLabel.text = dataSource.UserName;
        self.nameLabel.textColor = [UIColor colorWithHexString:@"#ffa044"];
        self.bgView.backgroundColor = [[UIColor colorWithHexString:@"#ffa044"] colorWithAlphaComponent:0.13];
    }else{
        if ([dataSource isKindOfClass:[MCXinZhiDuReportTotalModel class]]) {
            self.nameLabel.text = @"团队合计";
            self.nameLabel.textColor = [UIColor colorWithHexString:@"#ff4b50"];
            self.bgView.backgroundColor = [[UIColor colorWithHexString:@"#ff4b50"] colorWithAlphaComponent:0.13];
        }else{
            self.nameLabel.text = dataSource.UserName;
            self.bgView.backgroundColor = [UIColor colorWithHexString:@"#eff7ff"];
        }
        
        
        
    }
}


@end
